package com.xms.configuration.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xms.configuration.entity.Settings;
import com.xms.datacore.service.FinderService;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 * SettingFinderService
 * </p>
 *
 * @author migo
 * @since 2021/10/23
 */
@CacheConfig(cacheNames = "settings", keyGenerator = "CacheKeyGenerator")
@Service
public class SettingFinderService extends FinderService<Settings> implements ISettingFinderService {
    @Override
    @Cacheable(condition = "#id != null")
    public Settings getById(UUID id) {
        return super.getById(id);
    }

    @Override
    @Cacheable()
    public List<Settings> getByIds(Collection<UUID> idList) {
        return super.getByIds(idList);
    }

    @Override
    @Cacheable()
    public Settings getOne(Wrapper<Settings> queryWrapper) {
        return super.getOne(queryWrapper);
    }

    @Override
    @Cacheable()
    public int count() {
        return super.count();
    }

    @Override
    @Cacheable()
    public int count(Wrapper<Settings> queryWrapper) {
        return super.count(queryWrapper);
    }

    @Override
    //@Cacheable()
    public List<Settings> list(Wrapper<Settings> queryWrapper) {
        return super.list(queryWrapper);
    }

    @Override
    @Cacheable()
    public List<Settings> all() {
        return super.list();
    }

    @Override
    @Cacheable()
    public List<Settings> getByNamespace(String nameSpace) {
        return super.list(new LambdaQueryWrapper<Settings>()
                .like(Settings::getName, nameSpace + ".%"));
    }
}
